# makefile: MYOS
# rockily 2007.1

VER=0.01
VERFIX=.$(VER)
RELEASE=../final

INCLUDE = "./"
CFLAGS  = -fpack-struct -std=c99 -c  -I$(INCLUDE)
LFLAGS  = -Ttext 0x40000 -e main
DYNOBJ  =  kernel.o   \
           system.o  \
           vesa.o  \
           io.o   \
           interrupt.o \
           mouse.o   \
	   keyboard.o \
	   message.o \
           floppy.o \
           dma.o \
           fat12.o \
           memory.o \
           string.o 


all: kernel.bin boot.bin setup.bin



boot.bin: boot.asm
	nasm -f bin boot.asm -o boot.bin
setup.bin: setup.asm
	nasm -f bin setup.asm -o setup.bin


kernel.asmo:kernel.asm
	nasm -f elf kernel.asm -o kernel.asmo
interrupt.asmo:interrupt.asm
	nasm -f elf interrupt.asm -o interrupt.asmo
mouse.asmo:mouse.asm
	nasm -f elf mouse.asm -o mouse.asmo
keyboard.asmo:keyboard.asm
	nasm -f elf keyboard.asm -o keyboard.asmo
floppy.asmo:floppy.asm
	nasm -f elf floppy.asm -o floppy.asmo    


.c.o:
	gcc $(CFLAGS) -c $<

kernel.bin:  $(DYNOBJ) kernel.asmo interrupt.asmo mouse.asmo keyboard.asmo floppy.asmo boot.bin setup.bin
	ld --Map kernel.map $(LFLAGS) -o KERNEL  $(DYNOBJ) kernel.asmo interrupt.asmo mouse.asmo keyboard.asmo floppy.asmo
	strip -O binary KERNEL
	mv KERNEL  $@
	cp boot.bin setup.bin kernel.bin ../final

#	cp secondboot.bin anos.sys
#	ld -N -Ttext=0x8000 start.o main.o -o anos.exe
#	objdump -d -S anos.exe > dump.txt
#	objcopy -O binary anos.exe anos.sys

anos.img: boot.bin KERNEL.IMG fdmake.exe
	cp fat_template.img anos.img
	fdmake anos.img --mbr boot.bin
	fdmake anos.img KERNEL.IMG KERNEL.IMG
	fdmake anos.img MONA.CFG MONA.CFG

clean:
	rm -f *.bin *.o
	rm kernel.bin



